package com.base.cn.platform.os.common.j2cache;

import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
import net.oschina.j2cache.CacheProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Map;
import java.util.function.Function;

/**
 * 自定义缓存接口
 *
 * @author s.li
 * @date 2019/05/10
 */
@Component
public class CustomCacheChannel {

    @Autowired
    private CacheChannel cacheChannel;

    public CacheObject get(String region, String key, boolean... cacheNullObject) {
        //HttpServletRequest request = WebUtils.getRequest();
        return cacheChannel.get(region, key, cacheNullObject);
    }

    public CacheObject get(String region, String key, Function<String, Object> loader, boolean... cacheNullObject) {
        return cacheChannel.get(region, key, loader, cacheNullObject);
    }

    public Map<String, CacheObject> get(String region, Collection<String> keys) {
        return cacheChannel.get(region, keys);
    }

    public Map<String, CacheObject> get(String region, Collection<String> keys, Function<String, Object> loader, boolean... cacheNullObject) {
        return cacheChannel.get(region, keys, loader, cacheNullObject);
    }

    public boolean exists(String region, String key) {
        return cacheChannel.exists(region, key);
    }

    public int check(String region, String key) {
        return cacheChannel.check(region, key);
    }

    public void set(String region, String key, Object value) {
        cacheChannel.set(region, key, value);
    }

    public void set(String region, String key, Object value, boolean cacheNullObject) {
        cacheChannel.set(region, key, value, cacheNullObject);
    }

    public void set(String region, String key, Object value, long timeToLiveInSeconds) {
        cacheChannel.set(region, key, value, timeToLiveInSeconds);
    }

    public void set(String region, String key, Object value, long timeToLiveInSeconds, boolean cacheNullObject) {
        cacheChannel.set(region, key, value, timeToLiveInSeconds, cacheNullObject);
    }

    public void set(String region, Map<String, Object> elements) {
        cacheChannel.set(region, elements);
    }

    public void set(String region, Map<String, Object> elements, boolean cacheNullObject) {
        cacheChannel.set(region, elements, cacheNullObject);
    }

    public void set(String region, Map<String, Object> elements, long timeToLiveInSeconds) {
        cacheChannel.set(region, elements, timeToLiveInSeconds);
    }

    public void set(String region, Map<String, Object> elements, long timeToLiveInSeconds, boolean cacheNullObject) {
        cacheChannel.set(region, elements, timeToLiveInSeconds, cacheNullObject);
    }

    public void evict(String region, String... keys) {
        cacheChannel.evict(region, keys);
    }

    public void clear(String region) {
        cacheChannel.clear(region);
    }

    public Collection<CacheChannel.Region> regions() {
        return cacheChannel.regions();
    }

    public void removeRegion(String region) {
        cacheChannel.removeRegion(region);
    }

    public Collection<String> keys(String region) {
        return cacheChannel.keys(region);
    }

    public void close() {
        cacheChannel.close();
    }

    public CacheProvider getL1Provider() {
        return cacheChannel.getL1Provider();
    }

    public CacheProvider getL2Provider() {
        return cacheChannel.getL2Provider();
    }
}
